package com.github.roc.security.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 描述: 用户信息获取实现
 * 包名: com.github.roc.security.config
 * 作者: ChenGuop.
 * 日期: 2018/10/18 下午4:57.
 * 项目名称: security-oam
 * 版本: 1.0
 * JDK: since 1.8
 */
//@Component
public class MyUserDetailsServiceImpl implements UserDetailsService {

  private Logger logger = LoggerFactory.getLogger(getClass());

  @Autowired
  PasswordEncoder passwordEncoder;
  //TODO 获取数据库用户
  @Override
  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    logger.info("登录用户名"+username);
    //用户名，密码，权限
    String password = passwordEncoder.encode("123456");
    logger.info("登录密码：" + password);
//    return new User(username, "123456", AuthorityUtils.createAuthorityList("admin"));
    //自定义实现UserDetails接口即可
    return new User(username, password, true,true,true,false, AuthorityUtils.createAuthorityList("admin"));
  }
}
